package o;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Point;
import android.graphics.Rect;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.System;
import android.view.View;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.HashMap;
import java.util.LinkedHashMap;

public class evt {
    private static HashMap<String, Integer> ˎ = new HashMap();
    private static HashMap<String, Integer> ˏ = new HashMap();
    private static HashMap<String, Integer> ॱ = new HashMap();

    static {
        ˏ.put("hw", Integer.valueOf(2));
        ˏ.put("tx", Integer.valueOf(0));
    }

    private static int ˎ(View view) {
        return (view == null || view.getVisibility() != 0) ? 0 : view.getHeight();
    }

    private static int ˋ(View view) {
        return (view == null || view.getVisibility() != 0) ? 0 : view.getWidth();
    }

    private static boolean ˋ(Rect rect) {
        if (rect.bottom <= 0 && rect.top <= 0) {
            return true;
        }
        if (rect.left <= 0 && rect.right <= 0) {
            return true;
        }
        if (rect.left <= 0 || rect.right <= 0 || rect.bottom <= 0 || rect.top <= 0) {
            return false;
        }
        return true;
    }

    public static int ˊ(View view) {
        int ˎ = ˎ(view);
        int ˋ = ˋ(view);
        if (ˎ == 0 || ˋ == 0) {
            return 0;
        }
        Rect rect = new Rect();
        if (view == null) {
            return 0;
        }
        view.getLocalVisibleRect(rect);
        if (ˋ(rect)) {
            return 0;
        }
        boolean isShowing;
        Rect rect2;
        int ˏ;
        int i;
        int ॱ;
        if (view.getContext() instanceof Activity) {
            ActionBar actionBar = ((Activity) view.getContext()).getActionBar();
            if (actionBar != null) {
                isShowing = actionBar.isShowing();
                if (!isShowing) {
                    rect2 = new Rect();
                    view.getGlobalVisibleRect(rect2, new Point());
                    ˏ = epv.ˏ();
                    if (rect2.top < ˏ) {
                        i = ˏ - rect2.top;
                        ॱ = ॱ(ˎ, ˋ, rect, i);
                        if (ॱ > 0) {
                            return ˏ(ˎ, ˋ, rect, i);
                        }
                        return ॱ;
                    }
                }
                i = 0;
                ॱ = ॱ(ˎ, ˋ, rect, i);
                if (ॱ > 0) {
                    return ॱ;
                }
                return ˏ(ˎ, ˋ, rect, i);
            }
        }
        isShowing = false;
        if (isShowing) {
            rect2 = new Rect();
            view.getGlobalVisibleRect(rect2, new Point());
            ˏ = epv.ˏ();
            if (rect2.top < ˏ) {
                i = ˏ - rect2.top;
                ॱ = ॱ(ˎ, ˋ, rect, i);
                if (ॱ > 0) {
                    return ˏ(ˎ, ˋ, rect, i);
                }
                return ॱ;
            }
        }
        i = 0;
        ॱ = ॱ(ˎ, ˋ, rect, i);
        if (ॱ > 0) {
            return ॱ;
        }
        return ˏ(ˎ, ˋ, rect, i);
    }

    private static int ॱ(int i, int i2, Rect rect, int i3) {
        int i4 = i * i2;
        if (ˎ(rect) && ˏ(rect)) {
            return (((i2 - rect.left) * ((i - rect.top) - i3)) * 100) / i4;
        }
        if (ˎ(rect) && ˎ(rect, i2)) {
            return ((((i - rect.top) - i3) * rect.right) * 100) / i4;
        }
        if (ॱ(rect, i) && ˎ(rect, i2)) {
            return ((rect.bottom * rect.right) * 100) / i4;
        }
        if (ॱ(rect, i) && ˏ(rect)) {
            return ((rect.bottom * (i2 - rect.left)) * 100) / i4;
        }
        return -1;
    }

    private static int ˏ(int i, int i2, Rect rect, int i3) {
        if (ˎ(rect)) {
            return (((i - rect.top) - i3) * 100) / i;
        }
        if (ॱ(rect, i)) {
            return (rect.bottom * 100) / i;
        }
        if (ˎ(rect, i2)) {
            return (rect.right * 100) / i2;
        }
        if (ˏ(rect)) {
            return ((i2 - rect.left) * 100) / i2;
        }
        if (i3 > 0) {
            return ((i - i3) * 100) / i;
        }
        return 100;
    }

    private static boolean ॱ(Rect rect, int i) {
        return rect.bottom > 0 && rect.bottom < i;
    }

    private static boolean ˎ(Rect rect) {
        return rect.top > 0;
    }

    private static boolean ˎ(Rect rect, int i) {
        return rect.right > 0 && rect.right < i;
    }

    private static boolean ˏ(Rect rect) {
        return rect.left > 0;
    }

    public static int ˎ() {
        Intent registerReceiver = ContentManager.getInstant().getContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
        if (registerReceiver == null) {
            return 0;
        }
        return (new SafeIntent(registerReceiver).getIntExtra("level", 0) * 100) / new SafeIntent(registerReceiver).getIntExtra("scale", 100);
    }

    public static void ˊ(String str, int i) {
        ॱ.put(str, Integer.valueOf(i));
    }

    public static int ˎ(String str) {
        if (ॱ.containsKey(str)) {
            return ((Integer) ॱ.get(str)).intValue();
        }
        return -1;
    }

    public static void ॱ(String str, int i) {
        if (i >= 0) {
            ˎ.put(str, Integer.valueOf(i));
        }
    }

    public static int ˊ(String str) {
        if (ˎ.containsKey(str)) {
            return ((Integer) ˎ.get(str)).intValue();
        }
        return 0;
    }

    public static void ॱ() {
        ॱ.clear();
    }

    public static void ˏ() {
        ˎ.clear();
    }

    public static boolean ˋ(Context context) {
        if (context == null) {
            return false;
        }
        try {
            if (System.getInt(context.getContentResolver(), "accelerometer_rotation") != 0) {
                return true;
            }
            return false;
        } catch (SettingNotFoundException e) {
            Logger.e("VideoUtil", "SettingNotFoundException: " + e.toString());
            return false;
        }
    }

    public static int ˋ(Activity activity) {
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        if (rotation == 1) {
            return 270;
        }
        if (rotation == 3) {
            return 90;
        }
        return 0;
    }

    public static void ॱ(evp o_evp, long j, int i) {
        if (j > 0) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            linkedHashMap.put("length", String.valueOf(j));
            linkedHashMap.put("service_type", String.valueOf(i));
            linkedHashMap.put("videoId", o_evp.ॱ());
            linkedHashMap.put("trace", o_evp.ˏ());
            linkedHashMap.put("logId", o_evp.ʼ());
            linkedHashMap.put("logSource", o_evp.ʽ());
            dgh.ˋ("video_playlength", linkedHashMap);
        }
    }

    public static void ˎ(evp o_evp, String str, String str2, String str3, String str4) {
        String valueOf = String.valueOf(ˋ());
        String ˏ = azc.ˎ().ˏ();
        String ॱ = dok.ॱ();
        String ˋ = dok.ˋ();
        String deviceId = UserSession.getInstance().getDeviceId();
        String valueOf2 = String.valueOf(new bjy(ContentManager.getInstant().getContext()).ॱ().ˏ);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("timeStamp", String.valueOf(System.currentTimeMillis()));
        linkedHashMap.put("appName", o_evp.ʻ());
        linkedHashMap.put("playUrl", o_evp.ˊ());
        linkedHashMap.put("videoId", o_evp.ॱ());
        linkedHashMap.put("spId", o_evp.ॱॱ());
        linkedHashMap.put("sdkVersion", valueOf);
        linkedHashMap.put("emuiVersion", ˏ);
        linkedHashMap.put("androidVersion", ॱ);
        linkedHashMap.put("model", ˋ);
        linkedHashMap.put("deviceId", deviceId);
        linkedHashMap.put("deviceType", valueOf2);
        linkedHashMap.put("playStartTime", str);
        linkedHashMap.put("playEndTime", str2);
        linkedHashMap.put("playTime", str3);
        linkedHashMap.put("contentDuration", str4);
        dgh.ˋ("action_video_end", linkedHashMap);
    }

    public static void ˊ(evp o_evp, int i) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("default", "default");
        linkedHashMap.put("videoId", o_evp.ॱ());
        linkedHashMap.put("videoUrl", o_evp.ˊ());
        linkedHashMap.put("appId", o_evp.ˎ());
        linkedHashMap.put("trace", o_evp.ˏ());
        linkedHashMap.put("logId", o_evp.ʼ());
        linkedHashMap.put("logSource", o_evp.ʽ());
        linkedHashMap.put("service_type", String.valueOf(i));
        linkedHashMap.put("spId", o_evp.ॱॱ());
        dgh.ˋ("video_autoplay", linkedHashMap);
    }

    public static void ˏ(int i, evp o_evp, int i2) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("errorcode", String.valueOf(i));
        if (o_evp != null) {
            linkedHashMap.put("videoId", o_evp.ॱ());
            linkedHashMap.put("videoUrl", o_evp.ˊ());
            linkedHashMap.put("logId", o_evp.ʼ());
            linkedHashMap.put("logSource", o_evp.ʽ());
        }
        linkedHashMap.put("service_type", String.valueOf(i2));
        dgh.ˋ("340401", linkedHashMap);
    }

    public static int ˋ() {
        try {
            return ContentManager.getInstant().getContext().getPackageManager().getPackageInfo(ContentManager.getInstant().getContext().getPackageName(), DnsConfig.MAX_CACHE_ENTRIES).versionCode;
        } catch (Throwable e) {
            Logger.ˋ("VideoUtil", "getVersionCode error.", e);
            return 0;
        }
    }

    public static String ˏ(String str) {
        Integer num = (Integer) ˏ.get(str);
        if (num != null) {
            return String.valueOf(num);
        }
        Logger.ˏ("VideoUtil", "can not get spId: " + str);
        return "";
    }
}
